#include "Engine.h"
#include <time.h>

Engine::Engine(RenderWindow* wnd){
    window = wnd;
    srand(time(NULL));
}
//------------------------------------------------
void Engine::drawSprite(string path, int x, int y){
    Texture *t;
    t = &textures[path];
    if( t->getSize().x == 0){
        t->loadFromFile(path);
        textures[path] = *t;
    }
    Sprite s;
    s.setTexture(*t);
    s.setPosition(x,y);
    window->draw(s);
}
//------------------------------------------------
void Engine::drawSprite(Sprite *s, int x, int y){
    s->setPosition(x,y);
    window->draw(*s);
}
//------------------------------------------------
void Engine::closeWindow(){
    window->close();
}
//------------------------------------------------
void Engine::clearWindow(){
    window->clear();
}
//------------------------------------------------
void Engine::renderWindow(){
    window->display();
}
//------------------------------------------------
bool Engine::isKeyPressed(char key){
    switch(key){
            case 'u':
                return Keyboard::isKeyPressed(Keyboard::Up);
                break;
            case 'd':
                return Keyboard::isKeyPressed(Keyboard::Down);
                break;
            case 'l':
                return Keyboard::isKeyPressed(Keyboard::Left);
                break;
            case 'r':
                return Keyboard::isKeyPressed(Keyboard::Right);
                break;
            case 'e':
                return Keyboard::isKeyPressed(Keyboard::Escape);
                break;
            case 's':
                return Keyboard::isKeyPressed(Keyboard::Space);
                break;
    }
}
//------------------------------------------------
bool Engine::isMouseClickInRect(int x, int y, int width, int height){
    if (IntRect(x, y, width, height).contains(Mouse::getPosition(*window)))
        return Mouse::isButtonPressed(Mouse::Left);
    else
        return false;
}
//------------------------------------------------
bool Engine::isWindowOpen(){
    return window->isOpen();
}
